var equipmentCon = module.exports;

//升级

//装备喂养
equipmentCon.feedEquipment(player, equipmentId, feedEquipmentId) {
    if (player.bag.getItemCount(equipmentId) === 0 || player.bag.getItemCount(feedEquipmentId) === 0) {
        //物品不存在
        return 2
    }
    if (equipmentId < 999999) {
        //是否是解封的装备
        return 3
    }
    equipment = player.itemsInfo(equipmentId)

    if (equipment.quality === 1) {
        //白色装备不能升级
        return 4
    }
    if (equipment.classLvl === 11 || equipment.state === 3) {
        //装备的级别已经满级或
        return 5
    }

    if (feedEquipmentId < 999999) {
        feedEquipment = global.equipments.get(id)
    } else {
        feedEquipment = player.itemsInfo(equipmentId)
    }

    if (equipment.type !== feedEquipment.type) {
        if (equipment.type < 20 || feedEquipment.type < 20) {
            //装备类型不相同
            return 6
        }
    }
    //喂养装备计算需要的铜钱 money=quality*lvl*100*lvl
    var money = feedEquipment.feedMoney;
    if (player.money < money) {
        //钱不够
        return 7
    }

    //经验 exp=lvl*2*quality
    var exp = feedEquipment.lvl * 2 * feedEquipment.quality
    if (feedEquipment.lvl < equipment.lvl - 3 || feedEquipment.lvl > equipment.lvl + 3) {
        exp = Math.floor(exp * 0.5)
    }
    if (feedEquipment.lvl >= equipment.lvl && feedEquipment.quality >= equipment.quality - 1) {
        var r = Math.random() * 100
        if (r < 20) {
            exp = exp * 2
        } else if (r < 40) {
            exp = exp * 1.5
        }
    }

    equipment.exp += exp;
    while (equipment.exp >= equipment.classExp && equipment.classLvl < 11) {
        equipment.classLvl += 1
        equipment.exp -= equipment.classExp
        equipment.classExp = Math.floor(equipment.classLvl * 4 * Math.pow(1.5, equipment.quality))
    }
    equipment.state = 3;
    player.saveBag();
    return 0;

}

//装备突破